import unittest
from .. import MahJong, Rule


class MyTestCase(unittest.TestCase):
    def test_something(self):
        # arrange
        mj = MahJong(Rule.testRule)
        insect5 = mj.tiles[:15]
        # art
        allInsect = MahJong.GetAllInsect(insect5, 11, 5)
        # assert
        self.assertEqual(3, len(allInsect))

    def test_IsAllMeld(self):
        # arrange
        tiles = []
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 1)] * 3)
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 2)] * 3)
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 3)] * 3)
        # art
        bIsAllMeld = MahJong.IsAllMeld(tiles)
        bIsAllMeldByFast = MahJong.IsAllMeldFast1(tiles)
        # assert
        self.assertEqual(True, bIsAllMeld)
        self.assertEqual(True, bIsAllMeldByFast)

    def test_IsHandHu(self):
        # arrange
        tiles = []
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 1)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 2)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 3)] * 4)
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Character, 1)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Character, 2)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Character, 3)] * 4)
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 4)] * 2)
        # art
        bHu = MahJong.IsHandHu(tiles)

        # assert

        # assert
        self.assertEqual(True, bHu)

    def test_GetNextEliment(self):
            # arrange
        tiles = [1, 2, 3, 4, 5]
        # act
        adjTiles = MahJong.GetNextEliment(tiles, 0)
        # assert
        self.assertEqual(adjTiles[0], 2)

    def test_GetNoneValueTiles(self):
        # arrange
        tiles = []
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 1)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 4)])
        # tiles.extend([MahJongTile(Kind.Dot,9)]*4)

        # tiles.extend([MahJongTile(Kind.Character,1)])
        # tiles.extend([MahJongTile(Kind.Character,2)])
        # tiles.extend([MahJongTile(Kind.Character,3)]*4)
        # tiles.extend([MahJongTile(Kind.Dot,4)]*2)
        # act
        singles = MahJong.GetNoneValueTiles(tiles)
        # assert
        self.assertEqual(len(singles), 2)
        self.assertEqual(singles[0], MahJong.MahJongTile(Rule.Kind.Dot, 1))

    def test_GetLargetMerds(self):
        # arrange
        tiles = []
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 1)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 1)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 1)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 4)] * 3)
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 9)] * 4)
        # act
        merds = MahJong.GetLargetMerds(tiles)
        for merd in merds:
            m = merd[0]
            print(m.type, m.rank)
        # assert
        self.assertEqual(len(merds), 9)

    def test_GetSortLeft(self):
        # arrage
        tiles = []
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 1)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 1)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 1)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 1)])
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 2)] * 4)
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 3)] * 4)
        tiles.extend([MahJong.MahJongTile(Rule.Kind.Dot, 9)] * 2)
        # act`
        left = MahJong.GetSortLeft(tiles)
        # assert
        self.assertEqual(len(left), 0)


if __name__ == '__main__':
    unittest.main()
